package org.ifi.xechecs.transtable;

public class TranspositionTable {
	private static long[] hashtable;
    private static int[] score; // Store score
    private static byte[] depth;
    private static byte[] flag;
    private static byte[] bestMove;
    
    private static int capacity; // The number of move to store    
    
    static {
    	capacity = 4194304;
    	hashtable = new long[capacity];
    	score = new int[capacity];
    	depth = new byte[capacity];
    	flag = new byte[capacity];
    	bestMove = new byte[capacity];
    	
    }
    
    public TranspositionTable(int capacity){
    	this.capacity = capacity;
    	hashtable = new long[this.capacity];
    	score = new int[this.capacity];
    	depth = new byte[this.capacity];
    	flag = new byte[this.capacity];
    	bestMove = new byte[this.capacity];
    }
    
    public static void store(long zobrist, byte d, int s, byte f, byte m){
    	int key = getKey(zobrist);
    	hashtable[key] = zobrist;
    	depth[key] = d;
    	score[key] = s;
    	flag[key] = f;
    	bestMove[key] = m;
    }
    
    public static boolean exists(long zobrist){
    	return hashtable[getKey(zobrist)] == zobrist;
    }
   
    public static int getScore(long zobrist) {
		return score[getKey(zobrist)];
	}

	public static byte getDepth(long zobrist) {
		return depth[getKey(zobrist)];	
	}

	public static byte getFlag(long zobrist) {
		return flag[getKey(zobrist)];
	}

	public static byte getBestMove(long zobrist) {
		return bestMove[getKey(zobrist)];
	}

	public static int getCapacity() {
		return capacity;
	}

	private static int getKey(long zobrist){
    	return (int)(zobrist % capacity);
    }
}
